package com.edu.service.impl;

import com.edu.mapper.MessageMapper;
import com.edu.service.MymessageService;
import com.edu.dto.MessageDTO;
import com.edu.pojo.Message;
import com.edu.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MymessageServiceImpl implements MymessageService {

    @Autowired
    private MessageMapper messageMapper;

    @Override
    public R sendMessage(MessageDTO messageDTO) {
        Message message = new Message();
        message.setTitle(messageDTO.getTitle());
        message.setContent(messageDTO.getContent());
        message.setSenderId("当前用户ID"); // 假设从上下文中获取当前用户ID
        message.setReceiverId(messageDTO.getReceiverId());
        message.setBroadcast(messageDTO.isBroadcast());

        int result = messageMapper.insertMessage(message);
        if (result > 0) {
            return R.ok("消息发送成功");
        } else {
            return R.error("消息发送失败");
        }
    }
}